import formatColumn from 'packages/BaseTableCell/formatColumn';
import { formatDate } from '@src/util/lang';
import i18n from '@src/locales'
// 高级搜索
export const getAdvancedFields = (
  vm,
  { tagList = [] }
) => {
  let that = vm;
  return [
    {
      fieldName: 'phone',
      displayName: i18n.t('common.paas.view.designer.rule.mobilePhoneNum'),
      formType: 'phone',
    },
    {
      fieldName: 'email',
      displayName: i18n.t('common.form.type.email'),
      formType: 'email',
      defineType: '',
    },
      {
        fieldName: 'userTag',
        displayName: i18n.t('portal.dataBoard.loginTable.tag'),
        formType: 'select',
        setting: {
          isMulti: true,
          isMultiFlag: true,
          dataSource: tagList,
        },
      },
      {
        fieldName: 'loginTime',
        displayName: i18n.t('portal.dataBoard.loginTable.loginTime'),
        formType: 'date',
        setting: {
          toString: true,
        },
      },
      {
        fieldName: 'loginProvince',
        displayName: i18n.t('portal.dataBoard.loginTable.loginProvince'),
        formType: 'text',
      },
      {
        fieldName: 'loginCity',
        displayName: i18n.t('portal.dataBoard.loginTable.loginCity'),
        formType: 'text',
      },
      {
        fieldName: 'knownCustomer',
        displayName: i18n.t('portal.dataBoard.loginTable.knownCustomer'),
        formType: 'select',
        setting: {
          isMulti: false,
          dataSource: [
            {
              text: i18n.t('common.base.no'),
              value: 0,
            },
            {
              text: i18n.t('common.base.yes'),
              value: 1,
            },
          ],
        },
      },
      {
        fieldName: 'customer', // customerId
        displayName: i18n.t('common.form.type.customerName'),
        formType: 'text',
      },
      {
        fieldName: 'linkmanName',
        displayName: i18n.t('common.fields.contact.displayName'),
        formType: 'select',
      },
  ].map(item => {
    return {
      ...item,
      setting: item.setting || {},
      defaultValue: null,
      show: true,
      isSearch: 1,
      isNull: 1,
      isSystem: 1,
      orderId: 1,
    };
  });
};

// 列表 && 选择列
export const getColumnFields = vm => {
  const that = vm;

  return [
    {
      fieldName: 'memberName',
      displayName: i18n.t('portal.dataBoard.loginTable.memberName'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.memberName}</div>;
      },
    },
    {
      fieldName: 'phone',
      displayName: i18n.t('common.paas.view.designer.rule.mobilePhoneNum'),
      dataType: 'string'
    },
    {
      fieldName: 'email',
      displayName: i18n.t('common.form.type.email'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.email}</div>;
      },
    },
    {
      fieldName: 'tag',
      displayName: i18n.t('portal.dataBoard.loginTable.tag'),
      dataType: 'string',
    },
    {
      fieldName: 'loginTime',
      displayName: i18n.t('portal.dataBoard.loginTable.loginTime'),
      dataType: 'date',
      renderCell: (h, col, row) => {
          return <div>{formatDate(row.loginTime, 'YYYY-MM-DD HH:mm:ss')}</div>;
      },
    },
    {
      fieldName: 'loginAddress',
      displayName: i18n.t('portal.dataBoard.loginTable.loginAddress'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.loginProvince}{row.loginCity}</div>;
      },
    },
    {
      fieldName: 'knownCustomer',
      displayName: i18n.t('portal.dataBoard.loginTable.knownCustomer'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.knownCustomer ? '是' : '否'}</div>;
      },
    },
    {
      fieldName: 'customerName',
      displayName: i18n.t('common.form.type.customerName'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.customerName}</div>;
      },
    },
    {
      fieldName: 'linkmanName',
      displayName: i18n.t('common.fields.contact.displayName'),
      dataType: 'string',
      renderCell: (h, col, row) => {
          return <div>{row.linkmanName}</div>;
      },
    },
  ].map(item => {
    // 初始化属性
    let field = {
      ...item,
      formType: 'text',
      setting: item.setting || {},
      isNull: 1,
      isSearch: 1,
      orderId: 1,
      show: true,
      tableName: 'doorUser',
      minWidth: 150,
      visable: typeof item.visable == 'undefined' ? true : item.visable,
      isSystem:1
    };
    let formatField = formatColumn(field);
    return formatField
  });
};

export const getExportSystemInfo = () => {
  return [
    {
      exportAlias: 'memberName',
      displayName: i18n.t('portal.dataBoard.loginTable.memberName'),
    },
    {
        exportAlias: 'phone',
        displayName: i18n.t('common.fields.phone.displayName'),
    },
    {
        exportAlias: 'email',
        displayName: i18n.t('common.fields.email.displayName'),
    },
    {
      exportAlias: 'tag',
      displayName: i18n.t('portal.dataBoard.loginTable.tag'),
    },
    {
        exportAlias: 'loginTime',
        displayName: i18n.t('portal.dataBoard.loginTable.loginTime'),
    },
    {
        exportAlias: 'loginAddress',
        displayName: i18n.t('portal.dataBoard.loginTable.loginAddress'),
    },
    {
        exportAlias: 'knownCustomer',
        displayName: i18n.t('portal.dataBoard.loginTable.knownCustomer'),
    },
    {
        exportAlias: 'customerName',
        displayName: i18n.t('common.form.type.customerName'),
    },
    {
        exportAlias: 'linkmanName',
        displayName: i18n.t('common.fields.contact.displayName'),
    }
  ];
};
